using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace sharpTV.Entities
{
	/// <summary>
	/// Strongly-typed collection for the MediaSource class.
	/// </summary>
    [Serializable]
	public partial class MediaSourceCollection : ActiveList<MediaSource, MediaSourceCollection>
	{	   
		public MediaSourceCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>MediaSourceCollection</returns>
		public MediaSourceCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                MediaSource o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the sharpTV_MediaSources table.
	/// </summary>
	[Serializable]
	public partial class MediaSource : ActiveRecord<MediaSource>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public MediaSource()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public MediaSource(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public MediaSource(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public MediaSource(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("sharpTV_MediaSources", TableType.Table, DataService.GetInstance("sharpTVSubSonicProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarMediaSourceId = new TableSchema.TableColumn(schema);
				colvarMediaSourceId.ColumnName = "MediaSourceId";
				colvarMediaSourceId.DataType = DbType.Int32;
				colvarMediaSourceId.MaxLength = 0;
				colvarMediaSourceId.AutoIncrement = true;
				colvarMediaSourceId.IsNullable = false;
				colvarMediaSourceId.IsPrimaryKey = true;
				colvarMediaSourceId.IsForeignKey = false;
				colvarMediaSourceId.IsReadOnly = false;
				colvarMediaSourceId.DefaultSetting = @"";
				colvarMediaSourceId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarMediaSourceId);
				
				TableSchema.TableColumn colvarMediaSourceUId = new TableSchema.TableColumn(schema);
				colvarMediaSourceUId.ColumnName = "MediaSourceUId";
				colvarMediaSourceUId.DataType = DbType.Guid;
				colvarMediaSourceUId.MaxLength = 0;
				colvarMediaSourceUId.AutoIncrement = false;
				colvarMediaSourceUId.IsNullable = true;
				colvarMediaSourceUId.IsPrimaryKey = false;
				colvarMediaSourceUId.IsForeignKey = false;
				colvarMediaSourceUId.IsReadOnly = false;
				colvarMediaSourceUId.DefaultSetting = @"";
				colvarMediaSourceUId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarMediaSourceUId);
				
				TableSchema.TableColumn colvarChannelId = new TableSchema.TableColumn(schema);
				colvarChannelId.ColumnName = "ChannelId";
				colvarChannelId.DataType = DbType.Int32;
				colvarChannelId.MaxLength = 0;
				colvarChannelId.AutoIncrement = false;
				colvarChannelId.IsNullable = true;
				colvarChannelId.IsPrimaryKey = false;
				colvarChannelId.IsForeignKey = false;
				colvarChannelId.IsReadOnly = false;
				colvarChannelId.DefaultSetting = @"";
				colvarChannelId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarChannelId);
				
				TableSchema.TableColumn colvarFileName = new TableSchema.TableColumn(schema);
				colvarFileName.ColumnName = "FileName";
				colvarFileName.DataType = DbType.String;
				colvarFileName.MaxLength = 256;
				colvarFileName.AutoIncrement = false;
				colvarFileName.IsNullable = true;
				colvarFileName.IsPrimaryKey = false;
				colvarFileName.IsForeignKey = false;
				colvarFileName.IsReadOnly = false;
				
						colvarFileName.DefaultSetting = @"(N'')";
				colvarFileName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarFileName);
				
				TableSchema.TableColumn colvarMediaType = new TableSchema.TableColumn(schema);
				colvarMediaType.ColumnName = "MediaType";
				colvarMediaType.DataType = DbType.Int32;
				colvarMediaType.MaxLength = 0;
				colvarMediaType.AutoIncrement = false;
				colvarMediaType.IsNullable = true;
				colvarMediaType.IsPrimaryKey = false;
				colvarMediaType.IsForeignKey = false;
				colvarMediaType.IsReadOnly = false;
				colvarMediaType.DefaultSetting = @"";
				colvarMediaType.ForeignKeyTableName = "";
				schema.Columns.Add(colvarMediaType);
				
				TableSchema.TableColumn colvarDuration = new TableSchema.TableColumn(schema);
				colvarDuration.ColumnName = "Duration";
				colvarDuration.DataType = DbType.DateTime;
				colvarDuration.MaxLength = 0;
				colvarDuration.AutoIncrement = false;
				colvarDuration.IsNullable = true;
				colvarDuration.IsPrimaryKey = false;
				colvarDuration.IsForeignKey = false;
				colvarDuration.IsReadOnly = false;
				colvarDuration.DefaultSetting = @"";
				colvarDuration.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDuration);
				
				TableSchema.TableColumn colvarWidth = new TableSchema.TableColumn(schema);
				colvarWidth.ColumnName = "Width";
				colvarWidth.DataType = DbType.Int32;
				colvarWidth.MaxLength = 0;
				colvarWidth.AutoIncrement = false;
				colvarWidth.IsNullable = true;
				colvarWidth.IsPrimaryKey = false;
				colvarWidth.IsForeignKey = false;
				colvarWidth.IsReadOnly = false;
				
						colvarWidth.DefaultSetting = @"((0))";
				colvarWidth.ForeignKeyTableName = "";
				schema.Columns.Add(colvarWidth);
				
				TableSchema.TableColumn colvarHeight = new TableSchema.TableColumn(schema);
				colvarHeight.ColumnName = "Height";
				colvarHeight.DataType = DbType.Int32;
				colvarHeight.MaxLength = 0;
				colvarHeight.AutoIncrement = false;
				colvarHeight.IsNullable = true;
				colvarHeight.IsPrimaryKey = false;
				colvarHeight.IsForeignKey = false;
				colvarHeight.IsReadOnly = false;
				
						colvarHeight.DefaultSetting = @"((0))";
				colvarHeight.ForeignKeyTableName = "";
				schema.Columns.Add(colvarHeight);
				
				TableSchema.TableColumn colvarIsTradeMarked = new TableSchema.TableColumn(schema);
				colvarIsTradeMarked.ColumnName = "IsTradeMarked";
				colvarIsTradeMarked.DataType = DbType.Boolean;
				colvarIsTradeMarked.MaxLength = 0;
				colvarIsTradeMarked.AutoIncrement = false;
				colvarIsTradeMarked.IsNullable = true;
				colvarIsTradeMarked.IsPrimaryKey = false;
				colvarIsTradeMarked.IsForeignKey = false;
				colvarIsTradeMarked.IsReadOnly = false;
				
						colvarIsTradeMarked.DefaultSetting = @"((0))";
				colvarIsTradeMarked.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsTradeMarked);
				
				TableSchema.TableColumn colvarCreationDate = new TableSchema.TableColumn(schema);
				colvarCreationDate.ColumnName = "CreationDate";
				colvarCreationDate.DataType = DbType.DateTime;
				colvarCreationDate.MaxLength = 0;
				colvarCreationDate.AutoIncrement = false;
				colvarCreationDate.IsNullable = true;
				colvarCreationDate.IsPrimaryKey = false;
				colvarCreationDate.IsForeignKey = false;
				colvarCreationDate.IsReadOnly = false;
				
						colvarCreationDate.DefaultSetting = @"(getdate())";
				colvarCreationDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreationDate);
				
				TableSchema.TableColumn colvarOwner = new TableSchema.TableColumn(schema);
				colvarOwner.ColumnName = "Owner";
				colvarOwner.DataType = DbType.Guid;
				colvarOwner.MaxLength = 0;
				colvarOwner.AutoIncrement = false;
				colvarOwner.IsNullable = true;
				colvarOwner.IsPrimaryKey = false;
				colvarOwner.IsForeignKey = false;
				colvarOwner.IsReadOnly = false;
				colvarOwner.DefaultSetting = @"";
				colvarOwner.ForeignKeyTableName = "";
				schema.Columns.Add(colvarOwner);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["sharpTVSubSonicProvider"].AddSchema("sharpTV_MediaSources",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("MediaSourceId")]
		[Bindable(true)]
		public int MediaSourceId 
		{
			get { return GetColumnValue<int>(Columns.MediaSourceId); }
			set { SetColumnValue(Columns.MediaSourceId, value); }
		}
		  
		[XmlAttribute("MediaSourceUId")]
		[Bindable(true)]
		public Guid? MediaSourceUId 
		{
			get { return GetColumnValue<Guid?>(Columns.MediaSourceUId); }
			set { SetColumnValue(Columns.MediaSourceUId, value); }
		}
		  
		[XmlAttribute("ChannelId")]
		[Bindable(true)]
		public int? ChannelId 
		{
			get { return GetColumnValue<int?>(Columns.ChannelId); }
			set { SetColumnValue(Columns.ChannelId, value); }
		}
		  
		[XmlAttribute("FileName")]
		[Bindable(true)]
		public string FileName 
		{
			get { return GetColumnValue<string>(Columns.FileName); }
			set { SetColumnValue(Columns.FileName, value); }
		}
		  
		[XmlAttribute("MediaType")]
		[Bindable(true)]
		public int? MediaType 
		{
			get { return GetColumnValue<int?>(Columns.MediaType); }
			set { SetColumnValue(Columns.MediaType, value); }
		}
		  
		[XmlAttribute("Duration")]
		[Bindable(true)]
		public DateTime? Duration 
		{
			get { return GetColumnValue<DateTime?>(Columns.Duration); }
			set { SetColumnValue(Columns.Duration, value); }
		}
		  
		[XmlAttribute("Width")]
		[Bindable(true)]
		public int? Width 
		{
			get { return GetColumnValue<int?>(Columns.Width); }
			set { SetColumnValue(Columns.Width, value); }
		}
		  
		[XmlAttribute("Height")]
		[Bindable(true)]
		public int? Height 
		{
			get { return GetColumnValue<int?>(Columns.Height); }
			set { SetColumnValue(Columns.Height, value); }
		}
		  
		[XmlAttribute("IsTradeMarked")]
		[Bindable(true)]
		public bool? IsTradeMarked 
		{
			get { return GetColumnValue<bool?>(Columns.IsTradeMarked); }
			set { SetColumnValue(Columns.IsTradeMarked, value); }
		}
		  
		[XmlAttribute("CreationDate")]
		[Bindable(true)]
		public DateTime? CreationDate 
		{
			get { return GetColumnValue<DateTime?>(Columns.CreationDate); }
			set { SetColumnValue(Columns.CreationDate, value); }
		}
		  
		[XmlAttribute("Owner")]
		[Bindable(true)]
		public Guid? Owner 
		{
			get { return GetColumnValue<Guid?>(Columns.Owner); }
			set { SetColumnValue(Columns.Owner, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid? varMediaSourceUId,int? varChannelId,string varFileName,int? varMediaType,DateTime? varDuration,int? varWidth,int? varHeight,bool? varIsTradeMarked,DateTime? varCreationDate,Guid? varOwner)
		{
			MediaSource item = new MediaSource();
			
			item.MediaSourceUId = varMediaSourceUId;
			
			item.ChannelId = varChannelId;
			
			item.FileName = varFileName;
			
			item.MediaType = varMediaType;
			
			item.Duration = varDuration;
			
			item.Width = varWidth;
			
			item.Height = varHeight;
			
			item.IsTradeMarked = varIsTradeMarked;
			
			item.CreationDate = varCreationDate;
			
			item.Owner = varOwner;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varMediaSourceId,Guid? varMediaSourceUId,int? varChannelId,string varFileName,int? varMediaType,DateTime? varDuration,int? varWidth,int? varHeight,bool? varIsTradeMarked,DateTime? varCreationDate,Guid? varOwner)
		{
			MediaSource item = new MediaSource();
			
				item.MediaSourceId = varMediaSourceId;
			
				item.MediaSourceUId = varMediaSourceUId;
			
				item.ChannelId = varChannelId;
			
				item.FileName = varFileName;
			
				item.MediaType = varMediaType;
			
				item.Duration = varDuration;
			
				item.Width = varWidth;
			
				item.Height = varHeight;
			
				item.IsTradeMarked = varIsTradeMarked;
			
				item.CreationDate = varCreationDate;
			
				item.Owner = varOwner;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn MediaSourceIdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn MediaSourceUIdColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn ChannelIdColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn FileNameColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn MediaTypeColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn DurationColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn WidthColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn HeightColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        public static TableSchema.TableColumn IsTradeMarkedColumn
        {
            get { return Schema.Columns[8]; }
        }
        
        
        
        public static TableSchema.TableColumn CreationDateColumn
        {
            get { return Schema.Columns[9]; }
        }
        
        
        
        public static TableSchema.TableColumn OwnerColumn
        {
            get { return Schema.Columns[10]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string MediaSourceId = @"MediaSourceId";
			 public static string MediaSourceUId = @"MediaSourceUId";
			 public static string ChannelId = @"ChannelId";
			 public static string FileName = @"FileName";
			 public static string MediaType = @"MediaType";
			 public static string Duration = @"Duration";
			 public static string Width = @"Width";
			 public static string Height = @"Height";
			 public static string IsTradeMarked = @"IsTradeMarked";
			 public static string CreationDate = @"CreationDate";
			 public static string Owner = @"Owner";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
